import request from '@/utils/request'

/**
 * 获取用户权限列表
 */
export const getUserPermissionList = (userId: number) => {
  return request.get<PermissionResource[]>(`/api/user/${userId}/permissions`, { userId })
}

/**
 * 更新用户权限
 */
export const updateUserPermissions = (userId: number, permissionIds: number[]) => {
  return request.post<boolean>(`/api/user/${userId}/permissions`,{
      permissionIds
    })
}

/**
 * 获取用户角色权限树
 */
export const getUserRolePermissionTree = (roleId: number) => {
  return request.get<PermissionResource[]>(`/api/role/${roleId}/permissions/tree`,{ roleId })
}

/**
 * 获取所有权限资源树
 */
export const getAllPermissionTree = () => {
  return request.get<PermissionResource[]>('/api/resource/tree')
}

/**
 * 分配用户角色权限
 */
export const assignUserRolePermissions = (userId: number, roleId: number, permissionIds: number[]) => {
  return request.post<boolean>(`/api/user/${userId}/role/${roleId}/permissions`,{
      permissionIds
    })
}